package com.pmpd.activity.service.api.impl;

import com.pmpd.activity.constants.ActivityConstant;
import com.pmpd.activity.dao.HotActivityMapper;
import com.pmpd.activity.po.HotActivity;
import com.pmpd.activity.po.HotActivityExample;
import com.pmpd.activity.service.api.ApiHotActivityService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * \* User: helei
 * \* Date: 18/05/18
 * \* Description:
 * \
 */
@Service
public class ApiHotActivityServiceImpl implements ApiHotActivityService {

    @Resource
    private HotActivityMapper hotActivityMapper;

    @Override
    public List<HotActivity> selectByProjectId(String projectId, String language) {
        if (StringUtils.isBlank(projectId)) {
            return Collections.emptyList();
        }
        HotActivityExample example = new HotActivityExample();
        HotActivityExample.Criteria criteria = example.createCriteria();

        criteria.andProjectIdEqualTo(projectId);
        criteria.andLangEqualTo(language.toUpperCase());

        criteria.andUsableEqualTo(ActivityConstant.ACTIVITY_USABLE);
        example.setLimitStart(0);
        example.setLimitEnd(ActivityConstant.DEFAULT_API_MAX_PAGE_SIZE);
        example.setOrderByClause(ActivityConstant.DEFAULT_ORDER_BY_CLAUSE);
        return hotActivityMapper.selectByExample(example);
    }
}